# -*- coding:utf8 -*-

import urllib2
import BeautifulSoup

from util import console, text
from yos.yql import db
from yos.boss import ysearch

page = urllib2.urlopen('http://buzz.yahoo.com')
soup = BeautifulSoup.BeautifulSoup(page.read())
buzzlist = soup.find('table', id='top-searches')
tags = []
for mover in buzzlist.findAll('td'):
    if mover and mover.a:
        tags.append(mover.a.renderContents())



"""
def createXML(dict,xml):
    xmlout = _dict2xml.Dict2XML()
    xmlout.setXml(xml)
    return xmlout.dict2xml(dict)
"""

story = []

for item in tags:
    data = ysearch.search(item, vertical="news",count=1)
    news = db.create(data=data)
    print 'why is %s in news?' % item
    print 
    print news.rows[0]['abstract']
    print
    print
    #story.append(news.rows[0]['abstract'])


"""
print story

first_para = story[0:4]
second_para = story[4:7]
third_para = story[7:11]


print u",".join(first_para)
print
print
print u",".join(second_para)
print
print
print u",".join(third_para)
"""
